package com.gzx.spring.db.service.impl;

import java.time.LocalDateTime;

import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzx.risk.core.pojo.OrderInfo;
import com.gzx.spring.db.entity.OrderNotify;
import com.gzx.spring.db.mapper.OrderNotifyMapper;
import com.gzx.spring.db.service.OrderNotifyService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
@DS("risk")
public class OrderNotifyServiceImpl extends ServiceImpl<OrderNotifyMapper, OrderNotify> implements OrderNotifyService {
	@Override
	public boolean isNotified(String ordercode) {
		QueryWrapper<OrderNotify> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("ordercode", ordercode);
		long count = count(queryWrapper);
		return count > 0;
	}

	@Override
	public void addNotified(OrderInfo order) {
		OrderNotify notify = new OrderNotify();
		notify.setOrdercode(order.getOrdercode());
		notify.setNotifyStatus("notified");
		notify.setCreatedTime(LocalDateTime.now());
		this.save(notify);
	}

	@Override
	public long getOrderCount(LocalDateTime startTime, LocalDateTime endTime) {
		QueryWrapper<OrderNotify> queryWrapper = new QueryWrapper<>();
		queryWrapper.between("created_time", startTime, endTime);
		return count(queryWrapper);
	}
}
